<template>
  <ex_select_auto ref="main" :option="option" filterable remote remoteQuery="code"
    url="/wms-api/base/WmsBaseAlleyRpc/selectLabel.json" :value="value" :urlParams="_urlParams"
    :placeholder="$tt('tip_please_select_warehouse_alley')" @focus="_focus" :urlControl="urlControlFun" v-bind="$attrs"
    v-on="$listeners">
  </ex_select_auto>
</template>

<script>
export default {
  name: "base_alley_select",

  props: {
    value: null,
    checkArea: {
      type: Boolean,
      default: true,
    },
    warehouseId: {
      type: String,
    },
    areaId: {
      type: [String,],
    },
    option: {
      type: Object,
      default: () => {
        return { label: 'code', value: 'id' }
      }
    },
  },
  watch: {
    areaId: function (newVal, oldVal) {
      if (this.checkArea) {
        this.$nextTick(() => {
          const config = {}
          if (oldVal) {
            config.initValue = null
          }
          this.$refs.main.reloadData(config)
        })
      }

    },
  },
  methods: {
    _urlParams() {
      const out = {}
      if (this.areaId) out.areaId = this.areaId
      if (this.warehouseId) out.warehouseId = this.warehouseId
      return out
    },
    _focus() {
      if (this.checkArea) {
        return this.areaId ? null : this.$message.warning(this.$tt('tip_please_select_warehouse_area_first'))
      }
    },
    urlControlFun(params) {
      if (!this.checkArea) return true
      if (params.areaId) {
        return true
      } else {
        return {
          netStop: true,
          focusInnerData: [],
        }
      }
    },
  },
}
</script>

